#!/usr/bin python
# -*- coding: utf-8 -*-
# @Time    : 2024/5/16 15:10
# @Author  : hhr
from supervision_inspection.models import *


class SaveExcel():
    def SavePerformanceAllocation(self, file_table_rows, performance_year, performance_month, file_table, user):
        for t in range(4, file_table_rows):
            PerformanceAllocation.objects.create(apply_user=user, years=performance_year, month=performance_month, department_name=file_table.cell(t, 0).value, department_code=file_table.cell(t, 1).value,
                                                 department_director=file_table.cell(t, 2).value, job_number=int(file_table.cell(t, 3).value) if file_table.cell(t, 3).value else "", workload=file_table.cell(t, 4).value, synthesize=file_table.cell(t, 5).value,
                                                 department_total=file_table.cell(t, 6).value, director_performance=file_table.cell(t, 7).value, director_control_performance=file_table.cell(t, 8).value,
                                                 night_shift_performance=file_table.cell(t, 9).value, consultation_performance=file_table.cell(t, 10).value, outpatient_special_performance=file_table.cell(t, 11).value,
                                                 medical_community=file_table.cell(t, 12).value, other_single=file_table.cell(t, 13).value, talent_reserve=file_table.cell(t, 14).value,
                                                 special_performance=file_table.cell(t, 15).value, expected_performance=file_table.cell(t, 16).value)
            if file_table.cell(t, 3).value:
                DepartmentPerformanceAllocation.objects.create(assignor=User.objects.get(job_number=int(file_table.cell(t, 3).value)), years=performance_year, month=performance_month, department_code=file_table.cell(t, 1).value)

    def SavePerformanceAllocationClinical(self, file_table_rows, performance_year, performance_month, file_table, user):
        for t in range(3, file_table_rows):
            PerformanceAllocationClinical.objects.create(apply_user=user, years=performance_year, month=performance_month, department_name=file_table.cell(t, 0).value,
                                                         department_code=file_table.cell(t, 1).value, department_director=file_table.cell(t, 2).value, workload=file_table.cell(t, 3).value,
                                                         new_business=file_table.cell(t, 4).value, unit_checkup=file_table.cell(t, 5).value, apoplexy_stethalgia=file_table.cell(t, 6).value,
                                                         prevention_control=file_table.cell(t, 7).value, college_control=file_table.cell(t, 8).value, talent_reserve=file_table.cell(t, 9).value,
                                                         nursing_documents=file_table.cell(t, 10).value, departmental_disputes=file_table.cell(t, 11).value, department_total=file_table.cell(t, 12).value)

    def SavePerformanceAllocationTalentReserve(self, file_table_rows, performance_year, performance_month, file_table, user):
        for t in range(3, file_table_rows):
            PerformanceAllocationTalentReserve.objects.create(apply_user=user, years=performance_year, month=performance_month, department_name=file_table.cell(t, 0).value,
                                                         department_code=file_table.cell(t, 1).value, department_director=file_table.cell(t, 2).value, name=file_table.cell(t, 3).value,
                                                         title_level=file_table.cell(t, 4).value, technical_title=file_table.cell(t, 5).value, distribution_standards=file_table.cell(t, 6).value,
                                                         due_this_month=file_table.cell(t, 7).value, leave_days=file_table.cell(t, 8).value, start_time=file_table.cell(t, 9).value,
                                                         end_time=file_table.cell(t, 10).value, node=file_table.cell(t, 11).value)

    def SavePerformanceAllocationOtherSingleItems(self, file_table_rows, performance_year, performance_month, file_table, user):
        for t in range(3, file_table_rows):
            PerformanceAllocationOtherSingleItems.objects.create(apply_user=user, years=performance_year, month=performance_month, department_code=file_table.cell(t, 0).value,
                                                         department_name=file_table.cell(t, 1).value, job_number=int(file_table.cell(t, 2).value) if file_table.cell(t, 2).value else '', name=file_table.cell(t, 3).value,
                                                         news_day=file_table.cell(t, 4).value, spring_festival=file_table.cell(t, 5).value, total=file_table.cell(t, 6).value,
                                                         days=file_table.cell(t, 7).value, money=file_table.cell(t, 8).value, node=file_table.cell(t, 9).value)

    def SavePerformanceAllocationMedicalCommunity(self, file_table_rows, performance_year, performance_month, file_table, user):
        for t in range(3, file_table_rows):
            PerformanceAllocationMedicalCommunity.objects.create(apply_user=user, years=performance_year, month=performance_month, department_code=file_table.cell(t, 0).value,
                                                         department_name=file_table.cell(t, 1).value, total=file_table.cell(t, 2).value, node=file_table.cell(t, 3).value)

    def SavePerformanceAllocationOutpatientSpecialty(self, file_table_rows, performance_year, performance_month, file_table, user):
        for t in range(3, file_table_rows):
            PerformanceAllocationOutpatientSpecialty.objects.create(apply_user=user, years=performance_year, month=performance_month, department_code=file_table.cell(t, 0).value,
                                                         department_name=file_table.cell(t, 1).value, job_number=int(file_table.cell(t, 2).value) if file_table.cell(t, 2).value else '', doctor=file_table.cell(t, 3).value,
                                                         person_time=file_table.cell(t, 4).value, money=file_table.cell(t, 5).value, total_performance=file_table.cell(t, 6).value,
                                                         node=file_table.cell(t, 7).value)

    def SavePerformanceAllocationConsultationPerformance(self, file_table_rows, performance_year, performance_month, file_table, user):
        for t in range(3, file_table_rows):
            PerformanceAllocationConsultationPerformance.objects.create(apply_user=user, years=performance_year, month=performance_month, department_code=file_table.cell(t, 0).value,
                                                         ascription_department=file_table.cell(t, 1).value, job_number=int(file_table.cell(t, 2).value) if file_table.cell(t, 2).value else '', doctor=file_table.cell(t, 3).value,
                                                         quantity=file_table.cell(t, 4).value, performance_amount=file_table.cell(t, 5).value, node=file_table.cell(t, 6).value)

    def SavePerformanceAllocationNightShiftPerformance(self, file_table_rows, performance_year, performance_month, file_table, user):
        for t in range(4, file_table_rows):
            PerformanceAllocationNightShiftPerformance.objects.create(apply_user=user, years=performance_year, month=performance_month, department_category=file_table.cell(t, 0).value,
                                                         ascription_department=file_table.cell(t, 1).value, ascription_dep_code=file_table.cell(t, 2).value, department=file_table.cell(t, 3).value,
                                                         department_code=file_table.cell(t, 4).value, fixed_number=file_table.cell(t, 5).value, night_number=file_table.cell(t, 6).value,
                                                         night_standards=file_table.cell(t, 7).value, end_night_number=file_table.cell(t, 8).value, end_night_standards=file_table.cell(t, 9).value,
                                                         number_of_overnight_shifts=file_table.cell(t, 10).value, full_night_shift_standard=file_table.cell(t, 11).value,
                                                         month_days=file_table.cell(t, 12).value, labor_dispatch=file_table.cell(t, 13).value, floating_fee=file_table.cell(t, 14).value, actual_occurrence=file_table.cell(t, 15).value)

    def SavePerformanceAllocationDirectorPerformance(self, file_table_rows, performance_year, performance_month, file_table, user):
        for t in range(3, file_table_rows):
            PerformanceAllocationDirectorPerformance.objects.create(apply_user=user, years=performance_year, month=performance_month, department_code=file_table.cell(t, 0).value,
                                                         department_name=file_table.cell(t, 1).value, job_number=file_table.cell(t, 2).value, name=file_table.cell(t, 3).value,
                                                         position=file_table.cell(t, 4).value, duration_employment=file_table.cell(t, 5).value, department_category=file_table.cell(t, 6).value,
                                                         assessment_score=file_table.cell(t, 7).value, management_standards=file_table.cell(t, 8).value, attendance_days=file_table.cell(t, 9).value,
                                                         deduction_amount=file_table.cell(t, 10).value, quarterly_assessment=file_table.cell(t, 11).value, management_performance=file_table.cell(t, 12).value,
                                                         assessment_coefficient=file_table.cell(t, 13).value)

    def SavePerformanceAllocationComprehensiveTargetPerformance(self, file_table_rows, performance_year, performance_month, file_table, user, department_type):
        for t in range(3, file_table_rows):
            PerformanceAllocationComprehensiveTargetPerformance.objects.create(apply_user=user, years=performance_year, month=performance_month, department_name=file_table.cell(t, 0).value,
                                                         department_code=file_table.cell(t, 1).value, people_number=file_table.cell(t, 2).value, quality_dimension=file_table.cell(t, 3).value,
                                                         nursing_quality=file_table.cell(t, 4).value, medical_ethics=file_table.cell(t, 5).value, medical_insurance=file_table.cell(t, 6).value,
                                                         research_teaching=file_table.cell(t, 7).value, record_quality=file_table.cell(t, 8).value, score=file_table.cell(t, 9).value,
                                                         target_performance=file_table.cell(t, 10).value, department_score=file_table.cell(t, 11).value, nurse_score=file_table.cell(t, 12).value, department_type=department_type)

    def SavePerformanceAllocationNewTalentReserve(self, file_table_rows, performance_year, performance_month, file_table, user):
        for t in range(3, file_table_rows):
            PerformanceAllocationNewTalentReserve.objects.create(apply_user=user, years=performance_year, month=performance_month, department_code=file_table.cell(t, 0).value,
                                                         ascription_department=file_table.cell(t, 1).value, djob_number=int(file_table.cell(t, 2).value) if file_table.cell(t, 2).value else '', name=file_table.cell(t, 3).value,
                                                         title_level=file_table.cell(t, 4).value, technical_title=file_table.cell(t, 5).value, distribution_standards=file_table.cell(t, 6).value,
                                                         due_this_month=file_table.cell(t, 7).value, leave_days=file_table.cell(t, 8).value, start_time=file_table.cell(t, 9).value,
                                                         end_time=file_table.cell(t, 10).value, node=file_table.cell(t, 11).value, working_days=file_table.cell(t, 12).value)

